from django.db import models
from transmeta import TransMeta
from django.utils.translation import ugettext_lazy as _
from django.contrib.sites.models import Site
from django.utils.translation import get_language
from thumbs import ImageWithThumbsField

name="name_%s" % str(get_language())
# Create your models here.
class Serie(models.Model):
        __metaclass__ = TransMeta
        
        name = models.CharField(_("Name"), max_length=50, unique=True)
        slug = models.SlugField(_("Friendly URL"), max_length=30, unique=True)
        description = models.TextField(_("Description"))
        website = models.URLField(_("URL"))
        image = ImageWithThumbsField(_("Image"), upload_to='img/%Y/%m/%d', null=True, sizes=((110,150),))
        pub_date = models.DateTimeField(auto_now=True)
        
        def __unicode__(self):
                return self.name
                
        def get_search_text(self):
                return self.name + " " + self.description
                
        def get_absolute_url(self):
		site = Site.objects.get_current()
                return "http://%s/series/%s/" % (site.domain, self.slug)
        
        class Meta:
                ordering = [name]
                translate = ('name', 'description',)

class Capitulo(models.Model):
        __metaclass__ = TransMeta
        
        name = models.CharField(_("Name"), max_length=50)
        usa_date = models.DateField(_("USA date"))
        spain_date = models.DateField(_("Spain date"))
        url = models.URLField(_("URL"))
        serie = models.ForeignKey(Serie, related_name="capitulos")
        
        def __unicode__(self):
                return self.name
                
        def get_search_text(self):
                return self.name
                
        def get_absolute_url(self):
                return Serie.get_absolute_url(self.serie)+"episode/%i/" % self.id
                
        class Meta:
                translate = ('name', 'url',)